//
//  UIViewController+LZNavigationBarTransition.m
//  LYLazizDevelopDemo
//
//  Created by xbn_iMac on 2016/11/9.
//  Copyright © 2016年 XBN. All rights reserved.
//

#import "UIViewController+LZNavigationBarTransition.h"
#import <objc/runtime.h>
#import "LZSwizzle.h"
#import "UINavigationBar+BackgroundColor.h"

@implementation UIViewController (LZNavigationBarTransition)

+ (void)load {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        
        LZSwizzleMethod([self class],
                        @selector(viewDidAppear:),
                        @selector(LZ_viewDidAppear:));
        
    });
}

- (void)LZ_viewDidAppear:(BOOL)animated {
    if (![NSStringFromClass([self class]) hasPrefix:@"L"]) {
        // 针对于调用系统相册之类的适配navigationBar
        self.navigationItem.leftBarButtonItem.tintColor = UIColorFromRGB(0xffffff, 1);
        self.navigationItem.rightBarButtonItem.tintColor = UIColorFromRGB(0xffffff, 1);

        if([self isKindOfClass:NSClassFromString(@"MFMessageComposeViewController")] || [self isKindOfClass:NSClassFromString(@"SSPMailViewController")]) {
        }
        
        [self.navigationController.navigationBar lz_setSystemDefaultNavigationBar];
        // 针对于shareSDK里的ViewController适配navigationBar
        if ([NSStringFromClass([self class]) hasPrefix:@"SSP"]) {
            for (UIView *aView in self.navigationController.navigationBar.subviews) {
                if ([aView isKindOfClass:[UIButton class]]) {
                    UIButton *button = (UIButton*)aView;
                    [button setTitleColor:UIColorFromRGB(0xffffff, 1) forState:UIControlStateNormal];
                }
                else if ([aView isKindOfClass:[UILabel class]]) {
                    UILabel *label = (UILabel*)aView;
                    label.textColor = UIColorFromRGB(0xffffff, 1);
                }
            }
        }
    }
}

@end
